package com.lcj.demo.service;

import com.lcj.demo.domain.Department;
import com.lcj.demo.repository.DepartmentRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@Service
@Transactional
public class DepartmentService {
    private final DepartmentRepository departmentRepository;

    public DepartmentService(DepartmentRepository departmentRepository) {
        this.departmentRepository = departmentRepository;
    }

    public Department saveOrUpdate(Department department) {
        return departmentRepository.save(department);
    }

    @Transactional(readOnly = true) //只查询
    public List<Department> findAll() {
        return departmentRepository.findAll( );
    }

    public void delete(Long id) {
        departmentRepository.deleteById(id);
    }

}
